package com.rsk.service.impl;


import com.alibaba.dubbo.config.annotation.Service;
import com.rsk.dao.SysParamsConfigRepository;
import com.rsk.dao.extend.SysParamsConfigExtend;
import com.rsk.dao.utils.SearchDataUtils;
import com.rsk.entity.SysParamConfig;
import com.rsk.service.SysParamsConfigService;
import com.rsk.utils.algorithm.SnowflakeIdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service(interfaceClass = SysParamsConfigService.class)
public class SysParamsConfigServiceImpl implements SysParamsConfigService {

    @Autowired
    private SysParamsConfigRepository sysParamsConfigRepository;

    @Autowired
    private SysParamsConfigExtend sysParamsConfigExtend;

    @Autowired
    private SearchDataUtils searchDataUtils;

    public List<Map<String, Object>> selectSysParamsConfig(String paramName, String paramCode) {

       return sysParamsConfigRepository.selectSysParamsConfig(paramName,paramCode);
    }

    @Transactional
    public int saveSysParamsConfig(String paramName, Long id, String paramCode, Long operatorUser) {

        List<Map<String, Object>> list = sysParamsConfigRepository.selectSysParamsConfig(paramName,paramCode);

        SysParamConfig sysParamConfig = new SysParamConfig();
        if (list.isEmpty() || list.size() < 0) {
            sysParamConfig.setId(SnowflakeIdWorker.generateId(true));
            sysParamConfig.setParamName(paramName);
            sysParamConfig.setParamCode(paramCode);
            sysParamConfig.setOperatorUser(operatorUser);
            sysParamConfig.setOperatorTime(new Date());
            sysParamsConfigRepository.saveAndFlush(sysParamConfig);
            return 1;
        } else {
            return -1;
        }
    }

    @Transactional
    public int delSysParamsConfig(Long id,Long operatorUser) {

        return sysParamsConfigRepository.delSysParamsConfig(id,operatorUser);
    }

    @Transactional
    public int updateSysParamsConfig( Long id,String paramName, Long operatorUser) {

        return sysParamsConfigRepository.updateSysParamsConfig(id,paramName,operatorUser);
    }

}
